var saveReq = false;
//保存 草稿 
function autoSave(url, content){
//	var title=document.getElementById("title").value;
//	var content=document.getElementById("content").value;
	if(content!==null && url!==null) {		//当文章标题不为空时
//		var url = "saveDraft.jsp";
//		var param = "title="+title+"&content="+content;
		//调用编写的Ajax请求方法
//		console.log(content);
		saveReq = httpRequest("post",url,true,callbackFunc_save,content);
	}
}
//回调函数 
function callbackFunc_save(){
	if(saveReq.readyState == 4){
		if(saveReq.status == 200){
			var resLabel = document.getElementById("content").getElementsByTagName("label")[0];
//			document.getElementById("sysTip").innerHTML = saveReq.responseText;
//			document.getElementsByName("descr")[0].value = saveReq.responseText;
//			document.getElementById("content").getElementsByTagName("label")[0].innerText = "ok";
//			var descr = document.getElementsByName("descr")[0];
			var data = saveReq.responseText;
			if(data=="auto_save_success"){
				resLabel.innerText = data + " @ " + new Date();
			}else if(data=="auto_save_faild"){
				resLabel.innerText = data + " @ " + new Date();
			}else{
				console.log("unknown error");
			}
		}
	}
}

var delay=1000*5;		//定义延迟时间，这里为5分钟
function getParam(name){
	var dom = document.getElementsByName(name)[0];
	return dom.value;
}
/*var data = {
	"name":getParam("name"),
	"base_duration":getParam("base_duration"),
	"base_cost":getParam("base_cost"),
	"unit_cost":getParam("unit_cost"),
	"status":getParam("status"),
	"descr":getParam("descr"),
	"cost_type":getParam("cost_type"),
};*/
function makeParam(){
	return "name="+getParam("name")+"&base_duration="+getParam("base_duration")+"&base_cost="+getParam("base_cost")+"&unit_cost="+getParam("unit_cost")+"&descr="+getParam("descr")+"&cost_type="+getParam("cost_type");
};
timer=window.setInterval(function(){
	var data = makeParam();
	autoSave("addCostAutoSave",	data);
},delay);		//每隔5分钟保存一次草稿
//timer=window.setInterval(selectArticle,delay);		//每隔5分钟保存一次草稿